/**
 * 音频控制器
 */
define(function(){
	var Audio = function(){
		//常用标识
		this.audioEle = false;
		
		
		/**
		 * 初始化方法
		 * @param {String} audioId 音频标签Id
		 * @param {String} rsUrl 资源URL
		 */
		this.init = function(audioId,rsUrl){
			//设置URL
			this.audioEle = document.getElementById(audioId);
			this.__setResource(rsUrl);
            
            console.log('音频初始化');
    	}
		
		//私有方法
		/**
		 * 设置资源
		 * @param {String} rsUrl 资源URL
		 */
		this.__setResource = function(rsUrl){
			while (this.audioEle.firstChild) {
			    this.audioEle.removeChild(this.audioEle.firstChild);
			}
			
			var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
            var isFF = userAgent.indexOf("Firefox") > -1 ; //判断是否Firefox
            var isChrome = userAgent.indexOf("Chrome") > -1 ; //判断是否Chrome
            if (isChrome==false && isFF==false) {
            	this.audioEle.src = rsUrl + '/audio.aac';
            }else{
            	//更改为通过source加载
            	var x = document.createElement("SOURCE");
            	x.setAttribute("src", rsUrl + '/audio.ogg');
            	this.audioEle.appendChild(x);

           		var y = document.createElement("SOURCE");
            	y.setAttribute("src", rsUrl + '/audio.mp3');
            	this.audioEle.appendChild(y);

           		var z = document.createElement("SOURCE");
            	z.setAttribute("src", rsUrl + '/audio.aac');
            	this.audioEle.appendChild(z);
			}
		}
	};
	return Audio;
});